package com.tanhua.controller;

import com.tanhua.exception.BusinessExecption;
import com.tanhua.model.domain.ErrorResult;
import com.tanhua.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("user")
public class LoginController {

    @Autowired
    private UserService userService;


    /**
     * 发送短信登录
     *
     * @param map 手机号
     * @return
     */
    @RequestMapping("/login")
    public ResponseEntity login(@RequestBody Map map) {
//        获取手机号
        String phone = (String) map.get("phone");
        userService.sendMs(phone);
        return ResponseEntity.ok(null);
    }

    /**
     * 验证登录
     *
     * @param map
     * @return
     */
    @RequestMapping("/loginVerification")
    public ResponseEntity loginVerification(@RequestBody Map map) {
            String phone = (String) map.get("phone");
            String code = (String) map.get("verificationCode");
            Map retMap = userService.loginVerification(phone, code);
            return ResponseEntity.ok(retMap);
    }

}
